package com.yixiu.study.juc.thread;

/**
 * @CalssName T05_Join
 * @Description
 * @Author yixiu
 * @Date 2021/6/24 10:31
 * @Verison num1.0
 **/
public class T05_Join extends Thread{

    private int i;
    //上一个线程
    private Thread previousThread;

    public T05_Join(Thread previousThread,int i){
        this.previousThread=previousThread;
        this.i=i;
    }

    @Override
    public void run() {
        try {
            //调用上一个线程的join方法，大家可以自己演示的时候可以把这行代码注释掉
            previousThread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("num:"+i);
    }

    public static void main(String[] args) {
        Thread previousThread=Thread.currentThread();
        for(int i=0;i<100;i++){
            T05_Join joinDemo=new T05_Join(previousThread,i);
            joinDemo.start();
            previousThread=joinDemo;
        }
    }

}
